home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Draw / Include / DrawSelection.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  9.0 KB  |  294 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawSelection.h
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef DRAWSELECTION_H
  14. #define DRAWSELECTION_H
  15.  
  16. #ifndef SHAPES_H
  17. #include "Shapes.h"
  18. #endif
  19.  
  20. // ----- FrameWork Includes -----
  21.  
  22. #ifndef FWSELECT_H
  23. #include <FWSelect.h>
  24. #endif
  25.  
  26. // ----- OPF Foundation Includes -----
  27.  
  28. #ifndef BCCOLLU_H
  29. #include "BCCollU.h"
  30. #endif
  31.  
  32. #ifndef BCCOLLD_H
  33. #include "BCCollD.h"
  34. #endif
  35.  
  36. // ----- Graphic Includes -----
  37.  
  38. #ifndef FWCOLOR_H
  39. #include "FWColor.h"
  40. #endif
  41.  
  42. #ifndef FWRECT_H
  43. #include "FWRect.h"
  44. #endif
  45.  
  46. //==============================================================================
  47. //    •• Forward Declarations
  48. //==============================================================================
  49.  
  50. class CDrawPart;
  51. class CDrawFrame;
  52. class FW_CFacet;
  53. class CSelectionIterator;
  54. class CDrawSelection;
  55. class FW_CGraphicContext;
  56. class BC_CUnmanaged;
  57.  
  58. //==============================================================================
  59. //    •• class CDrawPublishLink
  60. //==============================================================================
  61.  
  62. class CDrawPublishLink : public FW_CPublishLink
  63. {
  64. public:
  65.     enum
  66.     {
  67.         kChunkSize = 3                // Chunk size for publish links
  68.     };
  69.  
  70.     CDrawPublishLink(XMPChangeID changeID, CDrawSelection *drawSelection);
  71.     virtual ~ CDECL CDrawPublishLink();
  72.     
  73.     virtual void    Publish();
  74.     virtual void    ExternalizeLinkContent(XMPStorageUnit* linkSU);
  75.     virtual XMPValueType GetPublishFormat();
  76.     
  77. private:
  78.     CDrawSelection*            fDrawSelection;
  79.     BC_TDynamicCollection<CBaseShape*, BC_CUnmanaged>*        fCollection;
  80. };
  81.  
  82. //==============================================================================
  83. //    •• class CDrawSubscribLink
  84. //==============================================================================
  85.  
  86. class CDrawSubscribLink : public FW_CSubscribLink
  87. {
  88. public:
  89.     enum
  90.     {
  91.         kChunkSize = 3                // Chunk size for subscribe links
  92.     };
  93.     
  94.     CDrawSubscribLink(XMPLink *xmpLink, CDrawSelection *drawSelection);
  95.     virtual ~CDrawSubscribLink();
  96.  
  97.     virtual void    Subscrib();
  98.     
  99. private:
  100.     CDrawSelection*            fDrawSelection;
  101.     BC_TDynamicCollection<CBaseShape*, BC_CUnmanaged>*        fCollection;
  102. };
  103.  
  104. //==============================================================================
  105. //    •• class CDrawSelection
  106. //==============================================================================
  107.  
  108. class CDrawSelection : public FW_CSelection
  109. {
  110. //------------------------------------------------------------------------------
  111. //    • Initialization/Destruction
  112. //
  113. public:
  114.     CDrawSelection();
  115.     void            InitDrawSelection(CDrawPart* drawPart);
  116.     virtual         ~CDrawSelection();
  117.     
  118. //------------------------------------------------------------------------------
  119. //    • Inherited API
  120. //
  121. public:
  122.     virtual void        CloseSelection();
  123.     virtual void        SelectAll();
  124.     virtual FW_Boolean    IsEmpty() const;
  125.     virtual FW_CProxyRun*    IsSelectionOnlyOneProxyRun() const;
  126.     virtual XMPShape*     GetSelectionShape();
  127.     
  128.     // ----- Cut/Copy/Paste/Clear -----
  129.     virtual FW_Boolean    DoClear();
  130.     virtual FW_Boolean    DoPaste();
  131.     virtual FW_Boolean    DoPasteWithLink();
  132.     
  133.     virtual void        ExternalizeSelection(XMPStorageUnit* storageUnit, FW_CFrame* commandFrame, XMPCloneKind kind);
  134.     virtual FW_Boolean    InternalizeSelection(XMPStorageUnit* storageUnit, XMPCloneKind kind);
  135.     virtual FW_Boolean    EmbedSelection(XMPPart* xmpPart, XMPShape* frameShape);
  136.  
  137.     // ----- Drag & Drop -----
  138.     virtual XMPRgnHandle CalcDragRgn(FW_CFacet* facet);
  139.     virtual FW_Boolean    DoDroppedInSameFrame(XMPStorageUnit* dropSU, FW_CFacet* facet, const FW_CPoint& originPoint, const FW_CPoint& dropPoint);
  140.     virtual FW_Boolean    DoDrop(XMPStorageUnit* dropSU, FW_CFacet* facet, const FW_CPoint& originPoint, const FW_CPoint& dropPoint);
  141.  
  142.      // ----- Linking -----
  143.     virtual FW_CPublishLink* NewPublishLink(XMPChangeID changeID);
  144.     virtual FW_CSubscribLink* NewSubscribLink(XMPLink *xmpLink);
  145.     virtual FW_Boolean        IsSelectionPublishable();
  146.     
  147. //------------------------------------------------------------------------------
  148. //    • New API
  149. //
  150. public:
  151.     CBaseShape*     WhichHandle(FW_CFacet* facet, const FW_CPoint& mouse, short& whichHandle) const;
  152.     
  153.     void            DrawSelectionHandles(FW_CFacet* facet, FW_Boolean turOn);
  154.     void            DrawHandles(CBaseShape* shape, FW_Boolean turOn);
  155.     void            DrawAllHandles(FW_CFrame* frame, FW_Boolean turOn);
  156.     
  157.     void            AddToSelection(CBaseShape* theShape, FW_Boolean drawHandles);
  158.     void            RemoveFromSelection(CBaseShape* theShape, FW_Boolean drawHandles);
  159.  
  160.     void            MapSelection(const FW_CRect& srcRect, const FW_CRect& dstRect);
  161.     void            OffsetSelection(XMPCoordinate xDelta, XMPCoordinate yDelta);
  162.  
  163.     void            Resize(FW_CGraphicContext* gc, short whichHandle, const FW_CPoint& firstPoint, XMPEventData event);    
  164.  
  165.     void            SelectWithRectangle(FW_CFacet* facet, const FW_CPoint& anchorPoint, XMPEventData event);
  166.  
  167.     void            ChangeSelectionPenSize(XMPCoordinate newPenSize);
  168.     void            ChangeSelectionFillFrame(unsigned short newFillFrame);
  169.     void            ChangeSelectionFillColor(const FW_CColor& color);
  170.     void            ChangeSelectionPenColor(const FW_CColor& color);
  171.  
  172.     FW_Boolean        HasProxySelected() const;
  173.     
  174.     unsigned long        Count() const;
  175.     
  176.     // ----- Frozen state -----
  177.     FW_Boolean        HasFrozen() const;
  178.     FW_Boolean        HasNotFrozen() const;
  179.     void            SetFrozen(FW_Boolean state);
  180.     
  181.     XMPShape*        GetUpdateShape() const;
  182.  
  183.     // ----- Anchor Shape -----
  184.     CBaseShape*        GetAnchorShape() const;
  185.     void            SetAnchorShape(CBaseShape* anchorShape);
  186.  
  187.     // ----- Publish -----
  188.     void            SelectionChanged();
  189.  
  190.     // ----- Insert Menu Item -----
  191.     virtual FW_Boolean    InsertNewPart();
  192.  
  193.     // ----- Selection Collection -----
  194.      BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>*    GetSelectionCollection() const;
  195.  
  196. private:
  197.     void            DragFeedback(FW_PlatformRegion dragRgn, short xDelta, short yDelta);
  198.     
  199.     void            CalcDragRect();
  200.     void            CalcUpdateShape();
  201.     void            CalcMapRect(short whichHandle, const FW_CPoint& handleCenter, XMPCoordinate penSize, FW_CRect* mapRect);
  202.     
  203.     void            RedrawShape(CBaseShape *shape);
  204.     
  205.     void            DoAdd(CBaseShape *shape);
  206.     void            DoRemove(CBaseShape *shape);
  207.     
  208.     void            AdjustSelectionAfterPaste();
  209.     
  210. //------------------------------------------------------------------------------
  211. //    • Data Members
  212. //
  213. private:
  214.     CDrawPart*            fDrawPart;
  215.     FW_CRect            fDragRect;
  216.     XMPShape*            fSelectionShape;
  217.     XMPShape*            fUpdateShape;
  218.     unsigned short            fProxyShapeCount;
  219.     unsigned short            fFrozenCount;
  220.     unsigned long            fCount;
  221.     CBaseShape*            fAnchorShape;
  222.     
  223.     BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>*    fCollection;
  224. };
  225.  
  226. //==============================================================================
  227. //    •• CDrawSelection Inlines
  228. //==============================================================================
  229.  
  230. //------------------------------------------------------------------------------
  231. //    • CDrawSelection::HasProxySelected
  232. //------------------------------------------------------------------------------
  233. inline FW_Boolean CDrawSelection::HasProxySelected() const
  234. {        
  235.     return fProxyShapeCount != 0;
  236. }
  237.  
  238. //------------------------------------------------------------------------------
  239. //    • CDrawSelection::GetUpdateShape
  240. //------------------------------------------------------------------------------
  241. inline XMPShape* CDrawSelection::GetUpdateShape() const
  242. {        
  243.     return fUpdateShape;
  244. }
  245.  
  246. //------------------------------------------------------------------------------
  247. //    • CDrawSelection::HasFrozen
  248. //------------------------------------------------------------------------------
  249. inline FW_Boolean CDrawSelection::HasFrozen() const
  250. {
  251.     return fFrozenCount != 0;
  252. }
  253.  
  254. //------------------------------------------------------------------------------
  255. //    • CDrawSelection::HasNotFrozen
  256. //------------------------------------------------------------------------------
  257. inline FW_Boolean CDrawSelection::HasNotFrozen() const
  258. {
  259.     return fCount != 0 && fFrozenCount != fCount;
  260. }
  261.  
  262. //------------------------------------------------------------------------------
  263. //    • CDrawSelection::Count
  264. //------------------------------------------------------------------------------
  265. inline unsigned long CDrawSelection::Count() const
  266. {
  267.     return fCount;
  268. }
  269.  
  270. //------------------------------------------------------------------------------
  271. //    • CDrawSelection::GetAnchorShape
  272. //------------------------------------------------------------------------------
  273. inline CBaseShape* CDrawSelection::GetAnchorShape() const
  274. {
  275.     return fAnchorShape;
  276. }
  277.  
  278. //------------------------------------------------------------------------------
  279. //    • CDrawSelection::SetAnchorShape
  280. //------------------------------------------------------------------------------
  281. inline void CDrawSelection::SetAnchorShape(CBaseShape* anchorShape)
  282. {
  283.     fAnchorShape = anchorShape;
  284. }
  285.  
  286. //------------------------------------------------------------------------------
  287. //    • CDrawSelection::GetSelectionCollection
  288. //------------------------------------------------------------------------------
  289. BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>*    CDrawSelection::GetSelectionCollection() const
  290. {
  291.     return fCollection;
  292. }
  293.  
  294. #endif